package com.yunxiang.summer.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.yunxiang.summer.R;
import com.yunxiang.summer.adapter.DynamicGroupAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView dynamicsRecyclerView;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 隐藏系统标题栏
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }

        // 初始化动态列表
        initDynamicsList();

    }

    /**
     * 初始化最近动态列表
     */
    private void initDynamicsList() {
        dynamicsRecyclerView = findViewById(R.id.rv_dynamics);
        dynamicsRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        // 模拟动态数据
        List<DynamicGroup> dynamicGroups = new ArrayList<>();

        // 今天的动态
        List<Dynamic> todayDynamics = new ArrayList<>();
        todayDynamics.add(new Dynamic(
                "上午在公园追蝴蝶，跑起来像小炮弹一样，笑个不停～",
                new int[]{R.mipmap.ic_launcher, R.mipmap.ic_launcher},
                "10:23"
        ));
        dynamicGroups.add(new DynamicGroup("今天", todayDynamics));

        // 昨天的动态
        List<Dynamic> yesterdayDynamics = new ArrayList<>();
        yesterdayDynamics.add(new Dynamic(
                "第一次自己用勺子吃完了一碗粥，虽然洒了点但超棒！",
                new int[]{R.mipmap.ic_launcher},
                "18:45"
        ));
        dynamicGroups.add(new DynamicGroup("昨天", yesterdayDynamics));

        // 设置适配器
        dynamicsRecyclerView.setAdapter(new DynamicGroupAdapter(this, dynamicGroups));
    }


    /**
     * 动态分组数据模型（按日期）
     */
    public static class DynamicGroup {
        private String date;
        private List<Dynamic> dynamics;

        public DynamicGroup(String date, List<Dynamic> dynamics) {
            this.date = date;
            this.dynamics = dynamics;
        }

        public String getDate() { return date; }
        public List<Dynamic> getDynamics() { return dynamics; }
    }

    /**
     * 单条动态数据模型
     */
    public static class Dynamic {
        private String content;
        private int[] imageList;
        private String time;

        public Dynamic(String content, int[] imageList, String time) {
            this.content = content;
            this.imageList = imageList;
            this.time = time;
        }

        public String getContent() { return content; }
        public int[] getImageList() { return imageList; }
        public String getTime() { return time; }
    }
}
